package com.scalar.chiptrack.sales.forms;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackActionForm;
import com.scalar.chiptrack.sales.EndUser;

/**
 * Author: Prabhanjan
 * Date: Mar 17, 2004
 * Time: 9:07:08 PM
 */

public class EndUserForm extends ChipTrackActionForm
{
    private String action = null;
    private int endUserId = -1;
    private EndUser endUser;

    public String getAction ()
    {
        return action;
    }

    /**
     * Get EndUser
     *
     * @return EndUser
     */
    public EndUser getEndUser ()
    {
        return endUser;
    }

    /**
     * Set the EndUser
     *
     * @param endUser
     */
    public void setEndUser ( EndUser endUser )
    {
        this.endUser = endUser;
    }

    /**
     * Set the action
     *
     * @param action
     */
    public void setAction ( String action )
    {
        this.action = action;
    }

    /**
     * Set the endUserId
     *
     * @return endUserId
     */
    public int getEndUserId ()
    {
        return endUserId;
    }

    /**
     * Set the endUserId
     *
     * @param endUserId
     */

    public void setEndUserId ( int endUserId )
    {
        this.endUserId = endUserId;
    }

    /**
     * Reset all properties to their default values.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public void reset ( ActionMapping mapping, HttpServletRequest request )
    {
        //This is simple hack.. as the shipping locations are becoming 0 everytime you click addshipping location
        ArrayList list = null;
        if ( endUser != null )
            list = this.endUser.getShippingLocations ();
        this.endUser = null;
        endUser = new EndUser ();
        endUser.setShippingLocations ( list );
    }


    /**
     * Validate the properties that have been set from this HTTP request,
     * and return an <code>ActionErrors</code> object that encapsulates any
     * validation errors that have been found.  If no errors are found, return
     * <code>null</code> or an <code>ActionErrors</code> object with no
     * recorded error messages.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
    public ActionErrors validate ( ActionMapping mapping,
                                   HttpServletRequest request )
    {

        ActionErrors errors = new ActionErrors ();

        return errors;

    }
}
